package base.action.lib;

import java.io.IOException;
import java.util.Date;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

import base.db.lib.DBHelper;
import base.db.lib.util.ConncenFactory;
import base.db.lib.util.DBConnection;

import javax.servlet.Filter;


/**
 * 加载数据源
 */
@SuppressWarnings("all")
public class StrutsFilter extends StrutsPrepareAndExecuteFilter {
	
	protected FilterConfig filterConfig = null;
	public void init(FilterConfig filterConfig) throws ServletException {
	   System.out.println("加载信息");
		super.init(filterConfig);
	}
	public void destroy() {
		this.filterConfig = null;
		super.destroy();
	}
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest)request;
		HttpRequestFactory.setRequest(req); //设置request
	    //System.out.println("begin:"+new Date().toLocaleString());
    	//ConncenFactory.setConnection(DBConnection.getConnection());//设置连接  
	 		chain.doFilter(request, response);
	    //System.out.println("end:"+new Date().toLocaleString());
	  //  super.doFilter(req, response, chain);
	}

}
